#include "XVertexBufferD3D9.h"

XVertexBufferD3D9::XVertexBufferD3D9(){
	m_buffer = NULL;
	u_size = 0;
}

XVertexBufferD3D9::~XVertexBufferD3D9(){
	if (m_buffer != NULL)
		m_buffer->Release();
}

bool XVertexBufferD3D9::Init(){
	return true;
}

string XVertexBufferD3D9::ToString(){
	return "XMod::XVertexBufferD3D9";
}
void XVertexBufferD3D9::SetVertexBuffer(XVertexBuffer* m_vertexbuffer){

}
void XVertexBufferD3D9::SetSourceBuffer(void* ptr_buffer,int i_offest,int i_size){
	if (ptr_buffer != NULL){
		byte* ptr_buffer_d3d;
		if (FAILED(m_buffer->Lock(i_offest, i_size, (void **)&ptr_buffer_d3d, 0)))
			return;
		memcpy(ptr_buffer_d3d, ptr_buffer, i_size);
		m_buffer->Unlock();
	}
}
void XVertexBufferD3D9::GetSourceBuffer(void** ptr_buffer){
	byte* ptr_buffer_d3d;
	if (FAILED(m_buffer->Lock(0, u_size, (void **)&ptr_buffer_d3d, 0))){
		ptr_buffer = NULL;
	}
	else{
		*ptr_buffer = malloc(u_size);
		memcpy(*ptr_buffer, ptr_buffer_d3d, u_size);
	}
}
IDirect3DVertexBuffer9* XVertexBufferD3D9::GetBufferD3D(){
	return m_buffer;
}

void XVertexBufferD3D9::SetBufferD3D(IDirect3DVertexBuffer9* buffer){
	m_buffer = buffer;
}